/*
 * Copyright 2008 Georgi Staykov
 * 
 * This file is part of pscoder.
 *
 * pscoder is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * pscoder is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with pscoder.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.gstaykov.pscoder.editor.syntax;

import java.util.StringTokenizer;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.swt.graphics.RGB;

import com.gstaykov.pscoder.Activator;
import com.gstaykov.pscoder.preferences.PreferenceConstants;

public class PowershellColors {
    private static Preferences preferences = Activator.getDefault().getPluginPreferences();
    static {
        preferences = Activator.getDefault().getPluginPreferences();
    }
    
	public static RGB COMMENT = getRGB(preferences.getString(PreferenceConstants.COLOR_COMMENT));
	public static RGB STRING = getRGB(preferences.getString(PreferenceConstants.COLOR_STRING));
	public static RGB VARIABLE = getRGB(preferences.getString(PreferenceConstants.COLOR_VARIABLE));
	public static RGB KEYWORD = getRGB(preferences.getString(PreferenceConstants.COLOR_KEYWORD));
	public static RGB DASH_KEYWORD = getRGB(preferences.getString(PreferenceConstants.COLOR_DASH_KEYWORD));
	public static RGB OTHER = getRGB(preferences.getString(PreferenceConstants.COLOR_OTHER));
	
	public static void reloadPreferences() {
	    preferences = Activator.getDefault().getPluginPreferences();
	    COMMENT = getRGB(preferences.getString(PreferenceConstants.COLOR_COMMENT));
	    STRING = getRGB(preferences.getString(PreferenceConstants.COLOR_STRING));
	    VARIABLE = getRGB(preferences.getString(PreferenceConstants.COLOR_VARIABLE));
	    KEYWORD = getRGB(preferences.getString(PreferenceConstants.COLOR_KEYWORD));
	    DASH_KEYWORD = getRGB(preferences.getString(PreferenceConstants.COLOR_DASH_KEYWORD));
	    OTHER = getRGB(preferences.getString(PreferenceConstants.COLOR_OTHER));
	}
	
	private static RGB getRGB(String prefInput) {
	    StringTokenizer st = new StringTokenizer(prefInput, ",");
	    int red = Integer.parseInt(st.nextToken());
        int green = Integer.parseInt(st.nextToken());
        int blue = Integer.parseInt(st.nextToken());
        
        return new RGB(red, green, blue);
	}
}
